<template>
    <view class="container data-v-6768d372">
        <view class="headimg-c data-v-6768d372">
            <button @chooseavatar="__e" class="data-v-6768d372" :data-event-opts="[['chooseavatar', [['onChooseAvatar', ['$event']]]]]" openType="chooseAvatar" :plain="true">
                <image class="data-v-6768d372" :src="form.headimg"></image>
                <view class="genghuan data-v-6768d372">更换头像</view>
            </button>
        </view>
        <view class="info-c data-v-6768d372">
            <view class="item data-v-6768d372">
                <view class="item-info data-v-6768d372">账户信息</view>
            </view>
            <view class="item data-v-6768d372">
                <view class="key data-v-6768d372">昵称</view>
                <input
                    @input="__e"
                    class="value data-v-6768d372"
                    :data-event-opts="[['input', [['__set_model', ['$0', 'name', '$event', []], ['form']]]]]"
                    placeholderStyle="text-align:left;color:#454551"
                    type="nickname"
                    :value="form.name"
                />
            </view>
            <view class="item data-v-6768d372">
                <view class="key data-v-6768d372">性别</view>
                <picker @change="__e" class="value data-v-6768d372" :data-event-opts="[['change', [['selectGender', ['$event']]]]]" mode="selector" :range="gender">
                    <view class="data-v-6768d372" style="display: flex; justify-content: flex-end; align-items: center">
                        <view class="uni-input data-v-6768d372">{{ gender[genderIndex] }}</view>
                        <text class="new-iconfont icon-arrow-right data-v-6768d372"></text>
                    </view>
                </picker>
            </view>
            <view class="item data-v-6768d372">
                <view class="key data-v-6768d372">手机</view>
                <view class="phone-c value data-v-6768d372" v-if="userInfo.phone">
                    <button
                        @getphonenumber="__e"
                        class="get-phone-btn data-v-6768d372"
                        :data-event-opts="[['getphonenumber', [['getPhoneNumber', ['$event']]]]]"
                        hoverClass="noen"
                        openType="getPhoneNumber"
                        :plain="true"
                        style="width: 100%; margin-left: 0"
                    >
                        <view class="data-v-6768d372" style="width: 100%; display: flex; align-items: center; justify-content: flex-end">
                            <view class="data-v-6768d372">{{ userInfo.phone }}</view>
                            <text class="new-iconfont icon-arrow-right data-v-6768d372"></text>
                        </view>
                    </button>
                </view>
                <button
                    @getphonenumber="__e"
                    class="get-phone-btn data-v-6768d372"
                    :data-event-opts="[['getphonenumber', [['getPhoneNumber', ['$event']]]]]"
                    hoverClass="noen"
                    openType="getPhoneNumber"
                    v-else
                >
                    授权
                </button>
            </view>
        </view>
        <view class="button-c data-v-6768d372">
            <button
                @confirm="__e"
                @tap="__e"
                class="submit-btn data-v-6768d372"
                :data-event-opts="[
                    ['confirm', [['', ['$event']]]],
                    ['tap', [['updateProfile', ['$event']]]]
                ]"
            >
                <text class="data-v-6768d372">保存</text>
            </button>
        </view>
        <view class="footer safe-area-bottom data-v-6768d372">
            <view @tap="__e" class="footer-button delete-btn data-v-6768d372" :data-event-opts="[['tap', [['handleDeleteAccount', ['$event']]]]]">
                <text class="data-v-6768d372">注销帐号</text>
            </view>
            <view @tap="__e" class="footer-button data-v-6768d372" :data-event-opts="[['tap', [['handleLogout', ['$event']]]]]">
                <text class="data-v-6768d372">退出登陆</text>
            </view>
        </view>
        <get-phone-popup
            @__l="
                __l($event, {
                    eventOpts: [
                        ['^success', [['getPhoneNumberSuccess']]],
                        ['^cancel', [['e0']]]
                    ]
                })
            "
            @cancel="
                __e($event, {
                    eventOpts: [
                        ['^success', [['getPhoneNumberSuccess']]],
                        ['^cancel', [['e0']]]
                    ]
                })
            "
            @success="
                __e($event, {
                    eventOpts: [
                        ['^success', [['getPhoneNumberSuccess']]],
                        ['^cancel', [['e0']]]
                    ]
                })
            "
            class="data-v-6768d372"
            :data-event-opts="[
                ['^success', [['getPhoneNumberSuccess']]],
                ['^cancel', [['e0']]]
            ]"
            vueId="573dfea2-1"
            v-if="isShowPhonePopup"
        ></get-phone-popup>
    </view>
</template>

<script>
import getPhonePopup from '@/components/GetPhonePopup/GetPhonePopup';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/myProfile/index'],
    {
        '6ce7': function (e, t, n) {
            'use strict';

            n.r(t);
            var o = n('ca9d');
            var i = n('f75a');
            for (var r in i) {
                if (['default'].indexOf(r) < 0) {
                    (function (e) {
                        n.d(t, e, function () {
                            return i[e];
                        });
                    })(r);
                }
            }
            n('ddfc');
            n('9bb5');
            var c = n('f0c5');
            var a = Object(c.a)(i.default, o.b, o.c, false, null, '6768d372', null, false, o.a, void 0);
            t.default = a.exports;
        },
        '81a8': function (e, t, n) {},
        '940f': function (e, t, n) {},
        '9bb5': function (e, t, n) {
            'use strict';

            var o = n('940f');
            n.n(o).a;
        },
        bd80: function (e, t, n) {
            'use strict';

            (function (e, o) {
                var i = n('4ea4');
                Object.defineProperty(t, '__esModule', {
                    value: true
                });
                t.default = void 0;
                var r = i(n('2eee'));
                var c = i(n('c973'));
                var a = i(n('9523'));
                function s(e, t) {
                    var n = Object.keys(e);
                    if (Object.getOwnPropertySymbols) {
                        var o = Object.getOwnPropertySymbols(e);
                        if (t) {
                            o = o.filter(function (t) {
                                return Object.getOwnPropertyDescriptor(e, t).enumerable;
                            });
                        }
                        n.push.apply(n, o);
                    }
                    return n;
                }
                var u = {
                    components: {},
                    data: function () {
                        return {
                            gender: ['男', '女', '保密'],
                            genderIndex: 0,
                            code: '',
                            isShowPhonePopup: false,
                            form: {
                                headimg: '',
                                name: '',
                                phone: '',
                                city: '',
                                gender: '',
                                email: '',
                                birthday: ''
                            }
                        };
                    },
                    computed: (function (e) {
                        for (var t = 1; t < arguments.length; t++) {
                            if (null != arguments[t]) {
                                var n = arguments[t];
                            } else {
                                var n = {};
                            }
                            if (t % 2) {
                                s(Object(n), true).forEach(function (t) {
                                    (0, a.default)(e, t, n[t]);
                                });
                            } else {
                                Object.getOwnPropertyDescriptors
                                    ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n))
                                    : s(Object(n)).forEach(function (t) {
                                          Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
                                      });
                            }
                        }
                        return e;
                    })({}, (0, n('26cb').mapGetters)(['userInfo', 'token'])),
                    watch: {
                        userInfo: function () {
                            this.initForm();
                        }
                    },
                    created: function () {
                        var that = this;
                        e.login({
                            success: function (e) {
                                that.code = e.code;
                            },
                            fail: function (e) {}
                        });
                    },
                    onLoad: function () {
                        var that = this;
                        return (0, c.default)(
                            r.default.mark(function t() {
                                return r.default.wrap(function (t) {
                                    for (;;) {
                                        switch ((t.prev = t.next)) {
                                            case 0:
                                                that.$store.dispatch('getUserInfo');
                                                that.initForm();
                                            case 2:
                                            case 'end':
                                                return t.stop();
                                        }
                                    }
                                }, t);
                            })
                        )();
                    },
                    methods: {
                        onChooseAvatar: function (t) {
                            console.log(t, '11');
                            var n = 'wechat-' + (e.getSystemInfoSync().appName || '') + '-miniapp-' + (e.getSystemInfoSync().platform || '');
                            var that = this;
                            o.uploadFile({
                                url: 'https://api.we213.fuzhouweiyi.top/image',
                                filePath: t.detail.avatarUrl,
                                name: 'image',
                                header: {
                                    Authorization: this.token || '',
                                    'Client-Type': n,
                                    'Client-Name': 'default',
                                    'content-type': 'multipart/form-data'
                                },
                                success: function (t) {
                                    e.showToast({
                                        title: '上传成功~',
                                        icon: 'none'
                                    });
                                    t.data;
                                    console.log('image=>', JSON.parse(t.data).data.image.url);
                                    that.form.headimg = JSON.parse(t.data).data.image.url;
                                },
                                fail: function (t) {
                                    e.showToast({
                                        title: t,
                                        icon: 'none'
                                    });
                                    console.log('fail:' + JSON.stringify(t));
                                }
                            });
                        },
                        bindInviter: function () {
                            var that = this;
                            e.showModal({
                                title: '请输入邀请码',
                                editable: true,
                                success: function (n) {
                                    if (n.confirm) {
                                        if (!n.content) {
                                            return false;
                                        }
                                        that.$http('/user/bind-inviter', 'POST', {
                                            invite_code: n.content
                                        }).then(function (n) {
                                            e.showToast({
                                                title: '绑定成功~',
                                                icon: 'none'
                                            });
                                            that.$store.dispatch('getUserInfo');
                                        });
                                    }
                                }
                            });
                        },
                        handleDeleteAccount: function () {
                            var that = this;
                            e.showModal({
                                title: '确定要删除帐号吗?',
                                content: '删除帐号后所有帐号资料将无法找回，请谨慎操作!',
                                confirmText: '仍然删除',
                                cancelText: '暂不删除',
                                success: function (n) {
                                    if (n.confirm) {
                                        e.showLoading({
                                            title: '申请中...'
                                        });
                                        that.$http('/user', 'DELETE').then(function (t) {
                                            e.hideLoading();
                                            e.showModal({
                                                title: '申请成功',
                                                content: '已为您申请删除帐号，待客服审核通过后帐号即会被删除~'
                                            });
                                        });
                                    }
                                }
                            });
                        },
                        handleLogout: function () {
                            var that = this;
                            e.showModal({
                                title: '确定要退出登录吗?',
                                confirmText: '退出登录',
                                cancelText: '暂不',
                                success: function (n) {
                                    if (n.confirm) {
                                        that.$store.dispatch('logout');
                                        e.showToast({
                                            title: '已退出登陆，跳转中~',
                                            icon: 'none'
                                        });
                                        setTimeout(function () {
                                            e.switchTab({
                                                url: '/pages/index/index'
                                            });
                                        }, 1800);
                                    }
                                }
                            });
                        },
                        startGetPhone: function () {
                            this.isShowPhonePopup = true;
                        },
                        getPhoneNumberSuccess: function (t) {
                            var that = this;
                            this.$http('/phone-update/with-code', 'POST', {
                                phone: t.phone,
                                phone_code: t.phone_code
                            }).then(function (t) {
                                that.$store.dispatch('getUserInfo');
                                e.showToast({
                                    title: '手机号更新成功~',
                                    icon: 'none'
                                });
                                that.isShowPhonePopup = false;
                            });
                        },
                        initForm: function () {
                            this.form.headimg = this.userInfo.headimg;
                            this.form.name = this.userInfo.name;
                            this.form.phone = this.userInfo.phone;
                            this.form.city = this.userInfo.city;
                            this.form.gender = this.userInfo.gender;
                            this.form.email = this.userInfo.email;
                            this.form.birthday = this.userInfo.birthday;
                            this.genderIndex = '男' === this.userInfo.gender ? 0 : 1;
                        },
                        updateProfile: function (t) {
                            console.log(t);
                            e.showLoading({
                                title: '更新中'
                            });
                            console.log(this.form);
                            this.$http({
                                url: '/user',
                                method: 'PUT',
                                data: this.form
                            })
                                .then(function (t) {
                                    e.hideLoading();
                                    e.showToast({
                                        title: '更新成功，跳转中~',
                                        icon: 'none'
                                    });
                                    setTimeout(function () {
                                        e.switchTab({
                                            url: '/pages/index/index'
                                        });
                                    }, 1300);
                                })
                                .catch(function (e) {});
                        },
                        selectBirthday: function (e) {
                            this.form.birthday = e.detail.value;
                        },
                        selectGender: function (e) {
                            this.genderIndex = e.detail.value;
                            this.form.gender = this.gender[this.genderIndex];
                        },
                        getPhoneNumber: function (t) {
                            var that = this;
                            if (t.detail.encryptedData) {
                                console.log('eeee', t);
                                this.$http('/phone-update/with-miniapp', 'POST', {
                                    encrypt_data: t.detail.encryptedData,
                                    iv: t.detail.iv,
                                    code: this.code
                                }).then(function (t) {
                                    that.$store.dispatch('getUserInfo');
                                    e.showModal({
                                        title: '手机号更新成功~',
                                        icon: 'none'
                                    });
                                    e.login({
                                        success: function (e) {
                                            that.code = e.code;
                                        },
                                        fail: function (e) {}
                                    });
                                });
                            }
                        }
                    },
                    onShow: function () {},
                    onPageScroll: function (e) {
                        this.scrollTop = e.scrollTop;
                    }
                };
                t.default = u;
            }.call(this, n('543d').default, n('bc2e').default));
        },
        ca9d: function (e, t, n) {
            'use strict';

            n.d(t, 'b', function () {
                return i;
            });
            n.d(t, 'c', function () {
                return r;
            });
            n.d(t, 'a', function () {
                return o;
            });
            var o = {
                GetPhonePopup: function () {
                    return n.e('components/GetPhonePopup/GetPhonePopup').then(n.bind(null, 'fc3f'));
                }
            };
            var i = function () {
                var that = this;
                that.$createElement;
                that._self._c;
                that._isMounted ||
                    (that.e0 = function (t) {
                        that.isShowPhonePopup = false;
                    });
            };
            var r = [];
        },
        d2e9: function (e, t, n) {
            'use strict';

            (function (e, t) {
                var o = n('4ea4');
                n('18ba');
                o(n('66fd'));
                var i = o(n('6ce7'));
                e.__webpack_require_UNI_MP_PLUGIN__ = n;
                t(i.default);
            }.call(this, n('bc2e').default, n('543d').createPage));
        },
        ddfc: function (e, t, n) {
            'use strict';

            var o = n('81a8');
            n.n(o).a;
        },
        f75a: function (e, t, n) {
            'use strict';

            n.r(t);
            var o = n('bd80');
            var i = n.n(o);
            for (var r in o) {
                if (['default'].indexOf(r) < 0) {
                    (function (e) {
                        n.d(t, e, function () {
                            return o[e];
                        });
                    })(r);
                }
            }
            t.default = i.a;
        }
    },
    [['d2e9', 'common/runtime', 'common/vendor']]
]);
</script>
<style>
@import './index.css';
</style>
